'use strict';

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    baseController = require('../../../Base/server/controllers/BaseDoc.js');

var newModel = baseController.getBaseDocFields();
newModel.Code = {
    type: String,
    unique: '编码已存在',
    required: '请输入编码',
    trim: true
};
newModel.Name = {
    type: String,
    required: '请输入名称',
    trim: true
};

//上级部门
newModel.ParentDepartment = {
    type: Schema.ObjectId,
    ref: 'Department'
};

newModel.IsEffective = {
    type: Boolean
};

newModel.Remark = {
    type: String,
    default: '',
    trim: true
};

var departmentSchema = new Schema(newModel);
departmentSchema.index({Code: 1});

mongoose.model('Department', departmentSchema, 'Department');
